package com.jia.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jia.shop.entity.ShopType;
import com.jia.shop.mapper.ShopTypeMapper;
import com.jia.shop.service.ShopTypeService;
import org.springframework.stereotype.Service;

/**
 * (ShopType)表服务实现类
 *
 * @author makejava
 * @since 2024-10-03 20:14:07
 */
@Service("shopTypeService")
public class ShopTypeServiceImpl extends ServiceImpl<ShopTypeMapper, ShopType> implements ShopTypeService {


    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ShopType queryById(Long id) {
        return this.baseMapper.selectById(id);
    }

    /**
     * 分页查询
     *
     * @param shopType 筛选条件
     * @param page     分页对象
     * @return 查询结果
     */
    @Override
    public Page<ShopType> queryByPage(ShopType shopType, Page page) {
        QueryWrapper<ShopType> wrapper = new QueryWrapper<>();
        wrapper.likeRight(StringUtils.isNotEmpty(shopType.getName()), "name", shopType.getName());
        return this.baseMapper.selectPage(page, wrapper);
    }

    /**
     * 新增数据
     *
     * @param shopType 实例对象
     * @return 实例对象
     */
    @Override
    public ShopType insert(ShopType shopType) {
        this.baseMapper.insert(shopType);
        return shopType;
    }

    /**
     * 修改数据
     *
     * @param shopType 实例对象
     * @return 实例对象
     */
    @Override
    public ShopType update(ShopType shopType) {
        this.baseMapper.updateById(shopType);
        return this.queryById(shopType.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.baseMapper.deleteById(id) > 0;
    }
}
